/**
 * 用户身份的路由
 * @type {createApplication}
 */
const express = require('express');
const bodyParser = require('body-parser');

//获取中间件和工具类
const userMid = require('../middleware/userMid');
const orderMid = require('../middleware/orderMid');
const orderListMid = require('../middleware/orderListMid')
const utils = require('../common/utils');

const userAPP = express(); // 用户子应用

/**配置post*/
userAPP.use(bodyParser.urlencoded({ extended: false }));//解析post请求数据
userAPP.use(bodyParser.json());//数据JSON类型
/**配置post*/

/**
 * 用户信息完善
 */
userAPP.post('/perfect', [userMid.uUser], (request, response, next) => {
  if(request.affectR > 0) {   //如果受影响行数存在，即修改成功
    let data = {
      code: 200
    };
    response.status(200).send(data);
  } else { // 否则,即未修改成功,修改不成功,非代码服务器的问题
    let data = {
      code: 500
    };
    response.status(500).send(data);
  }
})

/**
 * 添加订单
 */
userAPP.post('/add-order', orderMid.sOrder, (request, response, next) => {
  if (request.add_oid) {
    let data = {
      code: 200,
      msg: '订单创建成功',
    }
    response.status(200).send(data)
  } else {
    let data = {
      code: 500,
      msg: '订单创建失败'
    }
    response.status(500).send(data)
  }
})

/**
 * 添加订单明细
 */
userAPP.post('/add-order_list', orderListMid.sOrderList, (request, response, next) => {
  if (request.add_olid) {
    let data = {
      code: 200,
      msg: '添加商品明细成功'
    }
    response.status(200).send(data)
  } else {
    let data = {
      code: 500,
      msg: '添加商品明细失败'
    }
    response.status(500).send(data)
  }
})



module.exports = userAPP;